package com.zr.lads.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.zr.lads.dao.BaseDao;
import com.zr.lads.dao.RoleDao;
import com.zr.lads.pojo.Role;

/**
 * 角色管理功能实现类
 * @author tang
 *
 * @param <T>
 */
@Repository("roleDao")
public class RoleDaoImpl<T> extends BaseDaoImpl<T> implements RoleDao<T> {

	@Resource
	private BaseDao<Role> baseDao;
	
	@Override
	public List<Role> getAllRoles(int start, int pageSize) {
		StringBuffer hql = new StringBuffer("from Role ");
		Object[] param = new Object[]{};
		List<Role> roles = baseDao.find(hql.toString(), param, start, pageSize);
		return roles;
	}

	@Override
	public int getAllRolesCount() {
		String hql = "select count(r.roleId) from Role r";
		return this.count(hql).intValue();
	}

	@Override
	public boolean updateRoleFunc(int roleId, String funcs) {
		boolean flag = false;
		try {
			Role role = baseDao.get(Role.class, roleId);
			role.setRoleFuncs(funcs);
			baseDao.update(role);
			flag = true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return flag;
	}

}
